package com.haima.utils;

import java.util.Random;

public class GenStr {
    public static String getRandomString(int length) {
        Random random = new Random();
        StringBuilder sb = new StringBuilder(length);

        for (int i = 0; i < length; i++) {
            // 随机生成大小写字母或数字
            int randomChar = random.nextInt(75) + 48;
            // 如果生成的数字是大于字母'Z'的ASCII码值，则生成大写字母
            if (randomChar > 90) {
                randomChar += 6;
            }
            // 如果生成的数字是大于'z'的ASCII码值，则生成小写字母
            if (randomChar > 122) {
                randomChar -= 26;
            }
            sb.append((char) randomChar);
        }
        return sb.toString();
    }
}
